<template>
	<view>
	</view>
</template>

<script>
	import http from "../../apis/http.js";
	import {
		mapState,
		mapMutations,
		mapGetters,
		mapActions
	} from 'vuex'
	
	export default {
		data() {
			return {
				query:{code:null,referenceId:null},
			};
		},
		onLoad(options) {
			console.log("options code:" + options.code);
			if (options && options.code) {
				this.query.code = options.code;
			}
			if(!!this.$store.state.referenceId){
				this.query.referenceId = this.$store.state.referenceId;
			}
			this.checkCode();
		},
		computed: {
			...mapState(["openId"]),
			...mapState(["isSilentLogin"]),
			...mapGetters(['hasLogin']),
		},
		methods: {
			async checkCode() {
				try {
					let data =null;
					if(this.$store.state.isSilentLogin){
						data = await this.$apis.getWxSilentCheckCode(this.query);
					}else{
						data = await this.$apis.getWxCheckCode(this.query);
					}
					//var userInfo = http.GET(`${config.baseUrl}/wxlogin/check/${config.appId}`, query);
					// 前端自动登录
					this.$store.commit("SET_TOKEN", data.token);
					this.$store.commit("SET_USERINFO", data.user || {});
					this.$store.commit("SET_EXPIRE_TIME", data.expireTime || 0);
					this.$store.commit("SET_GOODS_MSG_CACHE", null);
					uni.getStorage({key:'beforeLoginUrlQuery',
						success: (res) => {
							console.log(JSON.stringify(res));
							this.$mRouter.push({
								route: res.data.routesConfig,
								query: res.data.query,
							});					
						},
						fail: (res) => {
							console.log(JSON.stringify(res));
							this.$mRouter.switchTab({
								route: this.$mRoutesConfig.main,
								query: res.data.query,
							});					
						},
					});
					
				} catch (e) {
				}
			},
		}
	}
</script>

<style>
</style>
